﻿using System;
using System.Collections.Generic;
using Dost.Khcn.Data.EntityModel;
using Dost.Khcn.Data.Implements;
using Dost.Khcn.Data.Interfaces;

namespace Dost.Khcn.Biz
{
    public class QuocGiaBiz
    {
        #region Properties

        private IQuocGiaDao _quocGiaDao;
        private IQuocGiaDao QuocGiaData
        {
            get { return _quocGiaDao ?? (_quocGiaDao = new QuocGiaDao()); }
        }

        #endregion

        #region Constructors

        #endregion

        #region Methods

        public List<QuocGia> GetAllQuocGias()
        {
            return QuocGiaData.GetAll();
        }

        public object GetQuocGias(int startIndex, int pageSize, string sorting, string name)
        {
            try
            {
                int totalRecords;
                var quocGias = QuocGiaData.GetQuocGias(startIndex, pageSize, sorting, name, out totalRecords);
                return new { Result = "OK", Records = quocGias, TotalRecordCount = totalRecords };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        public QuocGia CreateQuocGia(QuocGia quocGia)
        {
            // validate inputs
            if (quocGia == null) return null;

            return string.IsNullOrEmpty(quocGia.Ten) ? null : QuocGiaData.AddQuocGia(quocGia);
        }

        public QuocGia GetById(int id)
        {
            return id > 0 ? QuocGiaData.GetById(id) : null;
        }

        public void UpdateQuocGia(QuocGia quocGia)
        {
            if (quocGia == null) return;

            QuocGiaData.UpdateQuocGia(quocGia);
        }

        public object DeleteQuocGia(int id)
        {
            try
            {
                QuocGiaData.DeleteQuocGia(id);
                return new { Result = "OK" };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        #endregion
    }
}
